/**
 * 有两个数字只出现了一次，其余数字都出现了两次
 * @param {数组} arr 
 */
function findNumAppearOnce(arr) {
    const length = arr.length;
    if (length < 2) {
        return null;
    }
    let EOR = 0;
    arr.forEach(e => {
        EOR = EOR ^ e;
    })

    console.log(EOR);

    let index=findFirstBitIs1(EOR);

    console.log(index);

    let num1=0,
        num2=0;
    
    arr.forEach(e=>{
        if(IsBit1(e,index)){
            num1=num1^e;
        }else{
            num2=num2^e;
        }
    })   

    return {
        num1:num1,
        num2:num2
    }
}

function IsBit1(num,index) {
    num=num>>index;
    return (num&1)==1;
}

function findFirstBitIs1(num) {
    let index=0;
    while ((num & 1) == 0 && num != 0){
        num=num>>1;
        index++;
    }
    return index;
}

/** test */
arr = [2, 4, 3, 6, 3, 2, 5, 5];
console.log(findNumAppearOnce(arr));